package com.pty.demo.behaviour.iterator;

import java.util.List;

/**
 * @author pengty
 * @date 2020/3/14
 */
public class CustomIteratorImpl implements Iterator {

    private List<Object> list;

    private int index = 0;

    public CustomIteratorImpl(List<Object> list) {
        this.list = list;
    }

    @Override
    public Object first() {
        index = 0;
        return list.get(index);
    }

    @Override
    public Object next() {
        return this.hasNext() ? list.get(index++) : null;
    }

    @Override
    public boolean hasNext() {
        return index < list.size();
    }
}
